#include<iostream>
#include<vector>
using namespace std;

int main()
{
	int n = 0;
	int ret = -0x3f3f3f3f;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> dp(n + 1);
	for (int i = 1; i <= n; i++)
	{
		dp[i] = max(dp[i - 1] + a[i - 1], a[i - 1]);
		ret = max(ret, dp[i]);
	}
	cout << ret << endl;
	return 0;
}